| Conditions | 1 |
| Paths | 1 |
| Total Lines | 107 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 4 | describe('little endiand and big endian', function() { |
||
| 5 | |||
| 6 | const byteData = require('../index.js'); |
||
| 7 | |||
| 8 | // 16-bit |
||
| 9 | it('should swap 2 16-bit unsigned ints (0s)', |
||
| 10 | function() { |
||
| 11 | assert.deepEqual(byteData.endianness( |
||
| 12 | [0, 0, 0, 0], 2), |
||
| 13 | [0, 0, 0, 0]); |
||
| 14 | }); |
||
| 15 | it('should swap 2 16-bit unsigned ints (1s)', function() { |
||
| 16 | assert.deepEqual(byteData.endianness( |
||
| 17 | [0, 1, 0, 1], 2), |
||
| 18 | [1, 0, 1, 0]); |
||
| 19 | }); |
||
| 20 | it('should swap 2 16-bit unsigned ints (1s)', function() { |
||
| 21 | assert.deepEqual(byteData.endianness( |
||
| 22 | [0, 1, 0, 1], 2), |
||
| 23 | [1, 0, 1, 0]); |
||
| 24 | }); |
||
| 25 | |||
| 26 | // 24-bit |
||
| 27 | it('should swap 2 24-bit unsigned ints (0s)', function() { |
||
| 28 | assert.deepEqual(byteData.endianness( |
||
| 29 | [0, 0, 0, 0, 0, 0], 3), |
||
| 30 | [0, 0, 0, 0, 0, 0]); |
||
| 31 | }); |
||
| 32 | it('should swap 2 24-bit unsigned ints (1s)', function() { |
||
| 33 | assert.deepEqual(byteData.endianness( |
||
| 34 | [1, 0, 0, 1, 0, 0], 3), |
||
| 35 | [0, 0, 1, 0, 0, 1]); |
||
| 36 | }); |
||
| 37 | it('should swap 2 24-bit unsigned ints (1s)', function() { |
||
| 38 | assert.deepEqual(byteData.endianness( |
||
| 39 | [0, 0, 1, 0, 0, 1], 3), |
||
| 40 | [1, 0, 0, 1, 0, 0]); |
||
| 41 | }); |
||
| 42 | it('should swap 3 24-bit unsigned ints', function() { |
||
| 43 | assert.deepEqual(byteData.endianness( |
||
| 44 | ["00","00","80" , "01","00","00", "ff", "ff", "7f"], 3), |
||
| 45 | ["80","00","00" , "00","00","01", "7f", "ff", "ff"]); |
||
| 46 | }); |
||
| 47 | |||
| 48 | // 32-bit |
||
| 49 | it('should swap 2 32-bit unsigned ints (0s)', function() { |
||
| 50 | assert.deepEqual(byteData.endianness( |
||
| 51 | [0, 0, 0, 0, 0, 0, 0, 0], 4), |
||
| 52 | [0, 0, 0, 0, 0, 0, 0, 0]); |
||
| 53 | }); |
||
| 54 | it('should swap 2 32-bit unsigned ints (1s)', function() { |
||
| 55 | assert.deepEqual(byteData.endianness( |
||
| 56 | [0, 0, 0, 1, 0, 0, 0, 1], 4), |
||
| 57 | [1, 0, 0, 0, 1, 0, 0, 0]); |
||
| 58 | }); |
||
| 59 | it('should swap 2 32-bit unsigned ints (1s)', function() { |
||
| 60 | assert.deepEqual(byteData.endianness( |
||
| 61 | [1, 0, 0, 0, 1, 0, 0, 0], 4), |
||
| 62 | [0, 0, 0, 1, 0,0, 0, 1]); |
||
| 63 | }); |
||
| 64 | |||
| 65 | // 40-bit |
||
| 66 | it('should swap 2 40-bit unsigned ints (0s)', function() { |
||
| 67 | assert.deepEqual(byteData.endianness( |
||
| 68 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5), |
||
| 69 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
||
| 70 | }); |
||
| 71 | it('should swap 2 40-bit unsigned ints (1s)', function() { |
||
| 72 | assert.deepEqual(byteData.endianness( |
||
| 73 | [0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 5), |
||
| 74 | [1, 0, 0, 0, 0, 1, 0, 0, 0, 0]); |
||
| 75 | }); |
||
| 76 | it('should swap 2 40-bit unsigned ints (1s)', function() { |
||
| 77 | assert.deepEqual(byteData.endianness( |
||
| 78 | [1, 0, 0, 0, 0, 1, 0, 0, 0, 0], 5), |
||
| 79 | [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); |
||
| 80 | }); |
||
| 81 | |||
| 82 | // 48-bit |
||
| 83 | it('should swap 2 48-bit unsigned ints (0s)', function() { |
||
| 84 | assert.deepEqual(byteData.endianness( |
||
| 85 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 6), |
||
| 86 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
||
| 87 | }); |
||
| 88 | it('should swap 2 48-bit unsigned ints (1s)', function() { |
||
| 89 | assert.deepEqual(byteData.endianness( |
||
| 90 | [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], 6), |
||
| 91 | [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]); |
||
| 92 | }); |
||
| 93 | it('should swap 2 48-bit unsigned ints (1s)', function() { |
||
| 94 | assert.deepEqual(byteData.endianness( |
||
| 95 | [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], 6), |
||
| 96 | [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]); |
||
| 97 | }); |
||
| 98 | it('should swap a 48-bit unsigned int (120637438355317)', function() { |
||
| 99 | assert.deepEqual(byteData.endianness( |
||
| 100 | ["75", "e7", "a8", "17", "b8", "6d"], 6), |
||
| 101 | ["6d", "b8", "17", "a8", "e7", "75"]); |
||
| 102 | }); |
||
| 103 | |||
| 104 | // 64-bit |
||
| 105 | it('should turn a 64-bit float LE to BE', function() { |
||
| 106 | assert.deepEqual(byteData.endianness( |
||
| 107 | [24, 45, 68, 84, 251, 33, 9, 64], 8), |
||
| 108 | [64, 9, 33, 251, 84, 68, 45, 24]); |
||
| 109 | }); |
||
| 110 | }); |
||
| 111 |